// var a = 10;
// function a() { }
// console.log(typeof a)
// var obj = { a: 1, b: function () { console.log(this.a) } };
// var fun = obj.b;
// fun();
// function b() {
//     console.log(this);
// }
// b.call(null);
// console.log(null instanceof Object)//false
// console.log(typeof null)//object
// console.log(null === undefined)//false
// console.log(null == undefined)//true
// console.log((0xff) ^ 33)
// console.log(null == 0)//false
// console.log(typeof Date.now())//number
// console.log((4000 - 900 - 60 - 250 - 25 * 30) / 30)//一天多余的钱 68
// console.log('---------')
// var myArr = [1, 2, 3, 4, 5];

// myArr.shift();
// console.log(myArr)

// function* gen() {
//     yield 1;
//     yield 2;
//     yield 3;
// }
// console.log(gen())

// function fn(o, val) {
//     o.b = 1;
//     val = 1;
// }

// var obj = { b: 0 };
// var num = 0;
// fn(obj, num);
// console.log(obj, num);


// console.log(1 + "2" + "2");
// console.log(1 + +"2" + "2");
// console.log("A" - "B" + "2");
// console.log("A" - "B" + 2);

// function outer() {

//     var num = 0;

//     function inner() {

//         num++;

//         console.log(num);

//     }

//     return inner;

// }

// var f1 = outer();

// f1();

// f1();

// var f2 = outer();

// f2();

// f2();


let arr = []
let user = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
user.forEach(array => {
    arr.push(array)
})
console.log(arr)
user.forEach((value, index) => {
    console.log(value, index)
})
console.log(...user)//[ 1, 2, 3 ] [ 4, 5, 6 ] [ 7, 8, 9 ]
var gf = 123
var gf = 1234
console.log(gf)
console.log('--------------------------')
function sueForPeace(nums, target) {
    let obj = {},
        arr = [];

    for (i = 0; i < nums.length; i++) {
        let existence = nums.indexOf(target - nums[i]),
            isBoolean = existence > -1;
        if (isBoolean) {
            arr.push(i);
            arr.push(existence)
            return arr;
        } //obj[i + existence] = [existence, i]
    }

    // for (const key in obj) {
    //     if (Object.hasOwnProperty.call(obj, key)) arr.push(obj[key]);
    // }

    return arr;
}

var uname = "window";
var object = {
    uname: "object",
    fun: function () {
        console.log(this.uname);
        return function () {
            console.log(this.uname);
        }
    }
}

object.fun()();
var a = 1;
function fn() {
    var a = 2;
    function a() { console.log(3); }
    return a;
    function a() { console.log(4); }
}
var b = fn();
console.log(b);

console.log('------------')
const _getParams = (url) => {
    // 补全代码 url.slice(url.lastIndexOf('?') + 1) -> id=1&salas=1000
    let splitUrl = url.slice(url.lastIndexOf('?') + 1).split('&')
    console.log(splitUrl)
    let obj = {}
    splitUrl.map(n => {
        let [key, value] = n.split('=')
        obj[key] = value
    })
    console.log(obj)
    return obj
}
_getParams('https://nowcoder.com/online?id=1&salas=1000')

console.log(true + true + false)
let aa = [1, 2, 3]
let bb = [...aa]//把数组a的内容 挨个取出 放到b数组中
console.log(bb === aa) //false

let res = new Array(aa.length).fill(1)
console.log(res)
res.forEach((item, i) => {
    console.log(item, i, 1)
})

function fn() {
    console.log(this, 111)
}
let obj = {
    name: '谭梦寻'
}
fn() // 输出的是window全局对象
fn.call(obj) // 输出:{ name: '谭梦寻' } 111
function Father(uname, age, sex) {
    this.uname = uname;
    this.age = age;
    this.sex = sex;
}

function Son(uname, age, sex) {
    Father.call(this, uname, age, sex);
}
var son = new Son('刘德华', 18, '男');
console.log(son);
let arrA = []
console.log(!arrA, 123)
// var=TedECvqW8gdM13PDPdfZ%2bSAyApDC7vbqR2jJqYitBz2dtcrF%2fWzShWs8Jcv8IgNSCPjT95igtTJWcWx54Hxf826uqtRMyV4%2b59%2fKyRW0Eh0%3d
function utf8ToUnicode(utf8String) {
    return encodeURI(utf8String).toLowerCase();
}

// 示例使用 
var utf8String = "YMMU6070640";
var unicodeString = utf8ToUnicode(utf8String);
let urlCode = 'TedECvqW8gdM13PDPdfZ%2bSAyApDC7vbqR2jJqYitBz2dtcrF%2fWzShWs8Jcv8IgNSCPjT95igtTJWcWx54Hxf826uqtRMyV4%2b59%2fKyRW0Eh0%3d';
// console.log(unicodeString); // 输出: %e4%bd%a0%e5%a5%bd%ef%bc%8c%e4%b8%96%e7%95%8c%ef%bc%81
function toByte(data) {
    let parsedData = [];
    for (let i = 0, l = data.length; i < l; i++) {
        const byteArray = [];
        // charCodeAt() 方法可返回指定位置的字符的 Unicode 编码，返回值是 0 - 65535 
        // 之间的整数，表示给定索引处的 UTF-16 代码单元。
        const code = data.charCodeAt(i);

        // 十六进制转十进制：0x10000 ==> 65535  0x800 ==> 2048  0x80 ==> 128
        if (code > 0x10000) { // 4个字节
            // 0xf0 ==> 11110000 
            // 0x80 ==> 10000000

            byteArray[0] = 0xf0 | ((code & 0x1c0000) >>> 18); // 第 1 个字节
            byteArray[1] = 0x80 | ((code & 0x3f000) >>> 12); // 第 2 个字节
            byteArray[2] = 0x80 | ((code & 0xfc0) >>> 6); // 第 3 个字节
            byteArray[3] = 0x80 | (code & 0x3f); // 第 4 个字节

        } else if (code > 0x800) { // 3个字节
            // 0xe0 ==> 11100000
            // 0x80 ==> 10000000

            byteArray[0] = 0xe0 | ((code & 0xf000) >>> 12);
            byteArray[1] = 0x80 | ((code & 0xfc0) >>> 6);
            byteArray[2] = 0x80 | (code & 0x3f);

        } else if (code > 0x80) { // 2个字节
            // 0xc0 ==> 11000000
            // 0x80 ==> 10000000

            byteArray[0] = 0xc0 | ((code & 0x7c0) >>> 6);
            byteArray[1] = 0x80 | (code & 0x3f);

        } else { // 1个字节
            byteArray[0] = code;
        }
        parsedData.push(byteArray);
    }

    parsedData = Array.prototype.concat.apply([], parsedData);

    console.log('输出结果：', parsedData);
    console.log('转二进制：',
        parseInt(parsedData[0].toString(2)),
        parseInt(parsedData[1].toString(2)),
        parseInt(parsedData[2].toString(2)),
    );
}
// toByte(urlCode)
unescape(urlCode)
/*
var=TedECvqW8gdM13PDPdfZ%2bSAyApDC7vbqR2jJqYitBz2dtcrF%2fWzShWs8Jcv8IgNSCPjT95igtTJWcWx54Hxf826uqtRMyV4%2b59%2fKyRW0Eh0%3d
https://www.yangming.com/e-service/Track_Trace/mul_ctnr.aspx?
var=TedECvqW8gdM13PDPdfZ+SAyApDC7vbqR2jJqYitBz2dtcrF/WzShWs8Jcv8IgNSCPjT95igtTJWcWx54Hxf826uqtRMyV4+59/KyRW0Eh0=
*/
//www.yangming.com/e-service/Track_Trace/mul_ctnr.aspx?var=TedECvqW8gdM13PDPdfZ+SAyApDC7vbqR2jJqYitBz2dtcrF/WzShWs8Jcv8IgNSCPjT95igtTJWcWx54Hxf826uqtRMyV4+59/KyRW0Eh0=
console.log('------------');
function hasSmallDifference(arr, prop) {
    return arr.some((item, index) => {
        if (index > 0) {
            // 比较当前元素和前一个元素的指定属性
            const diff = Math.abs(item[prop] - arr[index - 1][prop]);
            if (diff < 0.01) {
                console.log(index, '索引')
            }
            return diff < 0.01;
        }
        return false;
    });
}

// 示例数组对象
const data = [{ value: 1.005 }, { value: 1.015 }, { value: 1.045 }, { value: 1.022 }, { value: 1.022 }];

// 检查数组中是否存在value属性值相差小于0.01
const hasSmallValueDifference = hasSmallDifference(data, 'value');

console.log(hasSmallValueDifference); // 输出：true 或 false
function hasSmall(arr) {
    let arrI = [];
    let arrJ = []
    for (let j = 0; j < arr.length; j++) {
        let index0 = arr[j].value;
        for (let i = j + 1; i < arr.length; i++) {
            if (Math.abs(index0 - arr[i].value) < 0.01) {
                arrJ.push(j)
                arrI.push(i)
            }
        }
    }
    return [...new Set([...arrI, ...arrJ])];
}
console.log(hasSmall(data), 111)
console.log(1 + (-0.5))

// 数组中slice方法
let arrT = [1, 2, 3, 4, 5]
let arrT2 = arrT.slice(1, 4)//只拷贝了数据没有拷贝地址
console.log(arrT)
console.log(arrT2)
arrT2[1] = 9
console.log(arrT)//[ 1, 2, 3, 4, 5 ]
console.log(arrT2)//[ 2, 9, 4 ]
